/**
 * 
 */
package net.cloudcodex.client.home.view.panel;

import java.util.ArrayList;
import java.util.List;

import net.cloudcodex.client.home.view.HomeView.Message;

import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.InlineHyperlink;
import com.google.gwt.user.client.ui.Label;

/**
 * This panel show if a new message / reply was posted
 * 
 * @author Daniel
 * 
 */
public class StoryResponsPanel extends HorizontalPanel implements HasClickHandlers {

	private List<String> charactersResponder;
	private Anchor seeMoreAnchor = new Anchor(true);
	private Message message;

	public void initPanel() {
		this.setStyleName("storyResponsPanel");
		Label textToDisplay = new Label();
		textToDisplay.setStyleName("responsLabel");
		textToDisplay.setText(getText());
		this.add(textToDisplay);
		seeMoreAnchor.setText(message.getSeeMore());
		seeMoreAnchor.addStyleName("seeMoreLabel");
		this.add(seeMoreAnchor);

	}

	private String getText() {
		String listUser;
		if (!charactersResponder.isEmpty()) {
			if (charactersResponder.size() > 1) {
				listUser = getListAsString() + " " + message.getHaveResponded();
			} else {
				listUser = getListAsString() + " " + message.getHasReplied();
			}
		}else{
			listUser = getListAsString(getList()) + " " + message.getHaveResponded();
		}

		return listUser;
	}

	private String getListAsString(List<String> list) {
		StringBuffer listAsText = new StringBuffer();
		for (String string : list) {
			listAsText.append(string + ",");
		}
		return listAsText.toString();
	}

	private List<String> getList() {
		List<String> result = new ArrayList<String>();
		result.add("toto");
		result.add("riri");
		result.add("fifi");
		result.add("loulou");
		return result ;
		
	}
	
	private String getListAsString() {

		return getListAsString(charactersResponder);
	}

	public void addStoryBoardResponse(List<String> charactersResponder) {
		this.charactersResponder = charactersResponder;
	}

	public void setMessage(Message message) {
		this.message = message;

	}

	@Override
	public HandlerRegistration addClickHandler(ClickHandler handler) {
		// TODO Auto-generated method stub
		return seeMoreAnchor.addClickHandler(handler);
	}

}
